var cb = require("./13_cb");

function sortedIndex(array, obj, iteratee, context) {
  iteratee = cb(iteratee, context, 1);
  var value = iteratee(obj);
  var low = 0,
    high = array.length - 1;

  while (low <= high) {
    // 注意这里呀
    var mid = Math.floor((low + high) / 2);
    if (array[mid] < value) {
      low = mid + 1; // 注意这里
    } else if (array[mid] > value) {
      high = mid;
    } else {
      return mid;
    }
  }

  return -1;
}

module.exports = sortedIndex;
